window.AvailabilityDetailQuery = (function($, module) {	
	var materialCode = $(".list_head").attr("id");
	var materialSpec = $("#materialSpec").attr("value");
	var materialModel = $("#materialModel").attr("value");
	var replaceMaterial = $("#replaceMaterial").attr("value");
	/**
	 * 初始化函数
	 */
	function init(){
		//bindEvent();	
		initPage(1);
	}
	
	/**
	 * 绑定事件
	 */
	function bindEvent(){
	   //页面加载数据
	   var url = 'inOutStockRecordQuery/queryInOutRecord';
	   var urlp = 'inOutStockRecordQuery/queryInOutRecord';
	   var paramData = CommonUtils.serializeToJSON($(".select_text input").serializeArray());
	   //paramData["pageNo"]	= $("#pageNo").val()||1;
	   paramData = JSON.stringify(paramData);
	   CommonUtils.getAjaxData({url:urlp,type:'POST',data:paramData},function(data){
			PageUtils.refreshPageInfo({element:'queryPage',data:paramData,url : url,callback : showBills},data['page']);
			showBills(data);
			updateColor();
	   });
		
	}
	
	function bindEvent1(){
		//页面加载数据
		var url = 'inOutStockRecordQuery/queryInOutRecord';
		var urlp = 'inOutStockRecordQuery/queryInOutRecord';
		var paramData = CommonUtils.serializeToJSON($(".select_text input").serializeArray());
		//paramData["pageNo"]	= $("#pageNo").val()||1;
		paramData = JSON.stringify(paramData);
		CommonUtils.getAjaxData({url:urlp,type:'POST',data:paramData},function(data){
			PageUtils.refreshPageInfo({element:'queryPage',data:paramData,url : url,callback : showBills},data['page']);
			showBills(data);
			updateColor();
		});
		
	}
	
	//默认加载  
    function initPage(pageNo){
    	 var paramData = CommonUtils.serializeToJSON($(".select_text input").serializeArray());
    	$.ajax({
            url:"inOutStockRecordQuery/queryInOutRecord/"+pageNo+"/10",
            type:"post",
            data:JSON.stringify(paramData),
            contentType:"application/json;charset=utf-8",
            success:function(data){
            	showBills(data);
        		$(".pager").Page({
        			totalPages: data.totalPage||0,//分页总数
        			liNums: 7,//分页的数字按钮数(建议取奇数)
        			activeClass: 'activP', //active 类样式定义
        			callBack : function(pageNo){
        				PageClick(pageNo);
        			}
        		}); 

            },
            error:function(data){
                alert("error");
            }
        });
    }
    
    //回调函数  
    function PageClick(pageNo) {  
        initPage(pageNo); 
    }
	
    $(".search").click(function(){
    	initPage(1);
    });
	//列表展示
	function showBills(data){
		$("#detailData").html("");
    	var datas = data['materialList'];
    	if(datas){
    		$.each(datas,function(item,obj){
    			var dom = "";
    			dom += "<tr class='listTableText list_list'>";
    			dom += "<td>"+CommonUtils.formatStr(obj.stage)+"</td>";
    			dom += "<td>"+CommonUtils.formatStr(obj.graphNumber)+"</td>";
    			dom += "<td>"+CommonUtils.formatStr(obj.materialName)+"</td>";
    			dom += "<td>"+CommonUtils.formatStr(obj.materialCode)+"</td>";
    			dom += "<td>"+CommonUtils.formatStr(obj.batchNo)+"</td>";
    			dom += "<td>"+CommonUtils.formatStr(obj.nums)+"</td>";
    			dom += "<td>"+(CommonUtils.formatStr(obj.type) == 1?'入库':'出库')+"</td>";		
    			dom += "<td>"+CommonUtils.formatTime(obj.storeName)+"</td>";
    			dom += "<td>"+CommonUtils.formatTime(obj.dt)+"</td><td id='flag' hidden>"+obj.flag+"</td>";			
    			dom += "</tr>";			
    			$("#detailData").append(dom);
    		});
    		$("tbody tr:odd").css("background","#EBF5FF");  	
    	}
    }
	
	function updateColor(){
		var tds = $("#detailData #flag");
		if(tds.length > 0){
			for(var i = 0;i<tds.length;i++){
				if(tds[i] != undefined && tds[i].innerText == "0")
					$(tds[i]).parent().css("background","#FF0000");
			}
		}
	}
	module.init = init;
	return module;
}($, window.AvailabilityDetailQuery || {}));
$(function() {
	AvailabilityDetailQuery.init();
});